import db from '@dfeidao/atom-nodejs/db';
import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import { systemid } from '../atom/config';
interface Message {
	productid: string;
	phone: string;
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string;
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:app-approval-details/s005,action_id:' + action_id);

	log('Service end path:app-approval-details/s005,action_id:' + action_id);
	const { exec, prepare } = db.query(action_id, session_id, systemid);
	const { exec: e, prepare: p } = db.query(action_id, session_id, '12');

	prepare('information_template', ['information_template_content'], { productid: message.productid, information_template_type: '7', information_template_status: '1' }, 199, 1, [], []);
	const [data] = await exec();

	// productid: 'U0000026'
	p('pub_user_thirdpart_openid', ['openid', 'usercode'], { productid: message.productid, usercode: message.phone }, 199, 1, [], []);
	const [opd] = await e();
	return {
		data: { data: data[0], data1: opd }
	};
}
